package 分类.回溯;

import java.util.LinkedList;
import java.util.List;

public class 组合 {
    static List<List<Integer>> res=new LinkedList<>();
    static LinkedList<Integer> track=new LinkedList<>();
    public static List<List<Integer>> combine(int n, int k) {
        backtrack(n,1,k);
        return res;
    }
    static void backtrack(int n,int start,int k){
        if(track.size()==k){
            res.add(new LinkedList<>(track));
        }
        for (int i=start;i<=n;i++){
            track.add(i);
            backtrack(n,i+1,k);
            track.removeLast();
        }
    }
    public static void main(String[] args) {

        List<List<Integer>> res1=combine(4,2);
        for (List<Integer> re : res1) {
            for (Integer integer : re) {

                System.out.print(integer);

            }
            System.out.println();
        }
    }

}
